package com.easysoft.framework.chat.service;

import com.easysoft.commons.utils.UUIDUtils;
import com.easysoft.framework.annotation.jdbc.DataSource;
import com.easysoft.framework.beans.Page;
import com.easysoft.framework.chat.mapper.SysChatrecordMapperExtd;
import com.easysoft.framework.chat.model.SysChatrecord;
import com.easysoft.framework.chat.model.SysChatrecordQuery;
import com.easysoft.framework.chat.model.SysChatrecordView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service("service.SysChatrecordService")
public class SysChatrecordService {
    @Autowired
    @Qualifier("mapper.SysChatrecordMapperExtd")
    private SysChatrecordMapperExtd sysChatrecordMapperExtd;

    @DataSource(DataSource.MASTER)
    public int addSysChatrecord(SysChatrecord entity){
        entity.setId(UUIDUtils.getUUID());
        entity.setCreateTime(new Date());
        return sysChatrecordMapperExtd.insertSelective(entity);
    }

    @DataSource(DataSource.MASTER)
    public int deleteSysChatrecord(String id){
        return sysChatrecordMapperExtd.deleteByPrimaryKey(id);
    }

    @DataSource(DataSource.MASTER)
    public int updateSysChatrecord(SysChatrecord entity){
        return sysChatrecordMapperExtd.updateByPrimaryKeySelective(entity);
    }

    @DataSource(DataSource.MASTER)
    public SysChatrecord selectSysChatrecordById(String id){
        return sysChatrecordMapperExtd.selectByPrimaryKey(id);
    }


    @DataSource(DataSource.SLAVE)
    public List<SysChatrecordView> selectSysChatrecordListByPage(SysChatrecordQuery query, Page page){
        int maxRow = sysChatrecordMapperExtd.selectCountSysChatrecord(query);
        page.setMaxRow(maxRow);

        if (maxRow == 0) {
            return new ArrayList<SysChatrecordView>();
        }
        return sysChatrecordMapperExtd.selectSysChatrecordListByPage(query,page);
    }
}
